* Set directories
*cd /Users/xiaosongw/Dropbox/Research/InformedSources/Replication/Analysis
*local datdir /Users/xiaosongw/Dropbox/Research/InformedSources/Replication/Build/Output/

cd /Users/byrned/Dropbox/Research/InformedSources/Replication/Analysis
local datdir "/Users/byrned/Dropbox/Research/InformedSources/Replication/Build/Output/"


*- Figure 1: Daily Station-Level Price Uploads to the Informed Sources Platform -*

* Load data, define sample
use `datdir'is_mel_p_2005_2019, clear
keep if t>=td(01oct2015) & t<=td(01oct2016)
	
* Dates for xlabels
local x1=td(1oct2015)
local x2=td(1nov2015)
local x3=td(1dec2015)
local x4=td(1jan2016)
local x5=td(1feb2016)
local x6=td(1mar2016)
local x7=td(1apr2016)
local x8=td(1may2016)
local x9=td(1jun2016)
local x10=td(1jul2016)
local x11=td(1aug2016)
local x12=td(1sep2016)
local x13=td(1oct2016)

* Manual upload dummy
gen nobs=1
replace nobs = 0 if missing(p)

* Electronic/manual uploads by market, brand, date
sort bid t id
collapse (sum) manual nobs, by(bid t)
tab bid
gen elec=nobs-manual

gen y1=37.5
gen y2=37.5
local xtext=td(01feb2016)
local panel1=td(15oct2015)
local panel2=td(12dec2015)-0.5
gen x1=`xtext'+54
gen x2=`xtext'+68

* ------------------------(a) Melbourne Electronic Uploads --------------------*

twoway 	(line elec t if bid==1, lwidth(medium) connect(stairstep) lcolor(gs0*0.85) lpattern(dash) ) ///
		(line elec t if bid==2, lwidth(medium) connect(stairstep) lcolor(gs0*0.7) lpattern(shortdash)) ///
		(line elec t if bid==3, lwidth(medthick) connect(stairstep) lcolor(gs0) lpattern(solid)) ///
		(line elec t if bid==4, lwidth(medium) connect(stairstep) lcolor(gs0*0.55) lpattern(dash_dot)) ///
		(line elec t if bid==5, lwidth(medium) connect(stairstep) lcolor(gs0*0.4) lpattern(longdash) ///		
		ytitle("Number of Stations with Electronic Prices Uploads", height(7)) ///
		ylabel(0(25)164,labsize(*0.8) grid) ///
		xlabel(`x1' `" "Oct 1"   "2015" "' `x2' `" "Nov 1"   "2015" "' `x3' `" "Dec 1"   "2015" "' ///
			   `x4' `" "Jan 1"   "2016" "' `x5' `" "Feb 1"   "2016" "' `x6' `" "Mar 1"   "2016" "' ///
			   `x7' `" "Apr 1"   "2016" "' `x8' `" "May 1"   "2016" "' `x9' `" "Jun 1"   "2016" "' ///
			   `x10' `" "Jul 1"   "2016" "' `x11' `" "Aug 1"   "2016" "' `x12' `" "Sep 1"   "2016" "' ///
			   `x13' `" "Oct 1"   "2016" "', labsize(*0.7)) xtitle("") ///
		plotregion(margin(zero) style(none) fcolor(white)) graphregion(color(white)) bgcolor(white) ///
		legend(order(1 2 3 4 5) ring(0) size(*0.75) position(12) symx(*0.5) region(lwidth(*0.05)) rows(1) ///
		label(1 BP) label(2 Caltex) label(3 Coles) label(4 Woolworths) label(5 7-Eleven))) ///
		(pcarrow y1 x1 y2 x2, color(black) lwidth(*1) barbsize(1) msize(2) ///
		text(37.5 `xtext' "Coles stops uploading" "station prices to the" "Informed Sources platform", justification(right) size(*0.75)) ///
		text(7.5 `panel1' "{bf:A}", justification(left) size(*2)) ///
		text(7.5 `panel2' "        Electronic Uploads", justification(left) size(*1.25)))
graph export Output/fig1a_elec.pdf, as(pdf) replace


local xtext=td(28jan2016)
replace x1=`xtext'+58
replace x2=`xtext'+72
local panel1=td(15oct2015)
local panel2=td(12dec2015)

twoway 	(line manual t if bid==1, lwidth(medium) connect(stairstep) lcolor(gs0*0.85) lpattern(dash) ) ///
		(line manual t if bid==2, lwidth(medium) connect(stairstep) lcolor(gs0*0.7) lpattern(shortdash)) ///
		(line manual t if bid==3, lwidth(medthick) connect(stairstep) lcolor(gs0) lpattern(solid)) ///
		(line manual t if bid==4, lwidth(medium) connect(stairstep) lcolor(gs0*0.55) lpattern(dash_dot)) ///
		(line manual t if bid==5, lwidth(medium) connect(stairstep) lcolor(gs0*0.4) lpattern(longdash) ///		
		ytitle("Number of Stations with Manual Prices Uploads", height(7)) ///
		ylabel(0(25)164,labsize(*0.8) grid ) ///
		xlabel(`x1' `" "Oct 1"   "2015" "' `x2' `" "Nov 1"   "2015" "' `x3' `" "Dec 1"   "2015" "' ///
			   `x4' `" "Jan 1"   "2016" "' `x5' `" "Feb 1"   "2016" "' `x6' `" "Mar 1"   "2016" "' ///
			   `x7' `" "Apr 1"   "2016" "' `x8' `" "May 1"   "2016" "' `x9' `" "Jun 1"   "2016" "' ///
			   `x10' `" "Jul 1"   "2016" "' `x11' `" "Aug 1"   "2016" "' `x12' `" "Sep 1"   "2016" "' ///
			   `x13' `" "Oct 1"   "2016" "', labsize(*0.7)) xtitle("") ///
		plotregion(margin(zero) style(none) fcolor(white)) graphregion(color(white)) bgcolor(white) ///
		legend(off)) ///
		(pcarrow y1 x1 y2 x2, color(black) lwidth(*1) barbsize(1) msize(2) ///
		text(37.5 `xtext' "Informed Sources reallocates" "price spotters to manually " "collect data on Coles stations", justification(right) size(*0.75))  ///
		text(157.5 `panel1' "{bf:B}", justification(left) size(*2)) ///
		text(157.5 `panel2' "   Manual Uploads", justification(left) size(*1.25)))
graph export Output/fig1b_manual.pdf, as(pdf) replace

